<template>
  <div>
      <el-button type="primary" size="small" @click="dialogFormVisible = true">添加商品</el-button>
       <el-dialog title="修改商品" :visible.sync="dialogFormVisible">
        <el-form :model="form">
          <el-form-item label="商品名">
            <el-input v-model="form.name" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="价格" >
            <el-input v-model="form.price" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="数量" >
            <el-input v-model="form.num" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="图片地址">
            <el-input v-model="form.picaddress" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="类型">
              <el-radio-group v-model="radio"  @change="$forceUpdate()">
                <el-radio  :label="item.type" :key="item.type" v-for="item in types">{{item.type_name}}</el-radio>
              </el-radio-group>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="addGoods()">确 定</el-button>
        </div>
      </el-dialog>
  </div>
</template>

<script>
export default {
    data(){
        return{
            dialogFormVisible:false,
            form:{
                name:'',
                price:'',
                num:'',
                picaddress:'',
                type:[],
                radio:0,
                shopid:0,
            },
            types:[],
            formLabelWidth:30,
        }
    },
    mounted(){
      this.getType()
      console.log(this.$route.query.id)
    },
    methods:{
        addGoods(){
          this.form.shopid = this.$route.query.id
          this.form.type = this.radio
          console.log(this.type)
            this.$axios.post('addGoods',this.form).then(resp=>{
                if(resp.status==200){
                    this.$message.success("添加成功")
                    this.dialogFormVisible = false
                }
            })
        },
        getType(){
        this.$axios.get('getAllTypes').then(resp=>{
          if(resp.status==200){
            this.types = resp.data.data
            console.log(this.types)
          }
          
        })
      },
    }
}
</script>

<style>

</style>